package com.meihua.pickerviewlibrary;

import android.content.Context;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/3.
 */

public class SymptomsPickerView extends OptionsPickerView<String> {
    private static final int TYPE_AGE = 1; //年龄
    private static final int TYPE_SEX = 2; //性别
    private static final int TYPE_CYCLE = 3; //周期

    // 类型存储集合
    private ArrayList<Map<String, String>> mRelative = new ArrayList<>();

    public SymptomsPickerView(Context context, List<String> commonList, int status) {
        super(context);
        initRelatives(commonList, status);
    }

    private void initRelatives(List<String> commonList, int status) {
        for (String age : commonList) {
            int indexOf = commonList.indexOf(age);
            Map<String, String> map=new HashMap<>();
            map.put("area_name", age);
            map.put("area_id", (indexOf+1) +"");
            mRelative.add(map);
        }
        switch (status) {
            case TYPE_AGE: //年龄
                setTitle("选择年龄");
                break;
            case TYPE_SEX: //性别
                setTitle("选择性别");
                break;
            case TYPE_CYCLE: //周期
                setTitle("选择生命周期");
                break;
        }
        setPicker(mRelative);
        setCyclic(false);
        setSelectOptions(0);
        setOnOptionsSelectListener(new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int option1, int option2, int option3) {
                if (mOnRelativeMoreListener != null){
                    mRelative.get(option1);
                    mOnRelativeMoreListener.onRelaviteSelectMore(mRelative.get(option1).get("area_name"), option1+1);
                }
            }
        });

    }

    //////////////////  定义回调接口  ///////////////////////////

    private OnRelativeMoreListener mOnRelativeMoreListener;

    public void setmOnRelativeMoreListener(OnRelativeMoreListener mOnRelativeMoreListener) {
        this.mOnRelativeMoreListener = mOnRelativeMoreListener;
    }

    public interface OnRelativeMoreListener {
        void onRelaviteSelectMore(String Relatives, int position);
    }
}
